<template>
  <div>
    <el-table :data="value.dataList">
      <el-table-column
        v-for="item in value.grid.normalitems"
        :key="item.Id"
        :prop="item.prop"
        :label="item.label"
        :width="item.width"
      />
      <el-table-column v-if="value.grid.operationitem.length > 0" label="操作" :width="value.grid.operationitem.length * 80">
        <template slot-scope="row">
          <el-button
            v-for="item in value.grid.operationitem"
            v-show="show(item.show,row.row)"
            :key="item.Id"
            type="text"
            @click="itemclick(item.method,row)"
          >
            <i class="el-icon--right" :class="item.icon" />&nbsp;{{ item.name }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row justify="end">
      <el-col style="text-align: right;">
        <el-pagination
          :current-page="value.pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="value.pageSize"
          :page-count="value.totalPage"
          :total="value.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
        />
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  props: {
    value: {
      type: Object,
      // eslint-disable-next-line vue/require-valid-default-prop
      default: {}
    }
  },
  methods: {
    // 每页数
    sizeChangeHandle(val) {
      this.value.pageSize = val
      this.value.pageIndex = 1
      this.$emit('searchmethod', this.searchelement)
    },
    // 当前页
    currentChangeHandle(val) {
      this.value.pageIndex = val
      this.$emit('searchmethod', this.searchelement)
      // this.getDataList()
    },
    show(method, row) {
      if (typeof (method) === 'function') {
        return method(row)
      } else {
        return true
      }
    },
    itemclick(method, row) {
      if (typeof (method) === 'function') {
        method(row.row)
      }
      // this.$emit(method, row)
    }
  }
}
</script>
